define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/withdraw/index' + location.search,
                    add_url: 'shop/withdraw/add',
                    // edit_url: 'shop/withdraw/edit',
                    del_url: 'shop/withdraw/del',
                    multi_url: 'shop/withdraw/multi',
                    agree_url: 'shop/withdraw/agree',
                    refuse_url: 'shop/withdraw/refuse',
                    import_url: 'shop/withdraw/import',
                    table: 'shop_withdraw',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'shop.shop_name', title: __('Shop.shop_name'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'shop_user_id', title: __('Shop_user_id')},
                        {field: 'shop_id', title: __('Shop_id')},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'handingfee', title: __('Handingfee'), operate:'BETWEEN'},
                        {field: 'taxes', title: __('Taxes'), operate:'BETWEEN'},
                        {field: 'type', title: __('Type'), operate: 'LIKE'},
                        {field: 'account', title: __('Account'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'memo', title: __('Memo'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'orderid', title: __('Orderid'), operate: 'LIKE'},
                        {field: 'transactionid', title: __('Transactionid'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"created":__('Status created'),"successed":__('Status successed'),"rejected":__('Status rejected')}, formatter: Table.api.formatter.status},
                        {field: 'transfertime', title: __('Transfertime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons:[
                                {
                                    name: 'agree',
                                    text: '同意',
                                    confirm:'确认同意打款吗?',
                                    icon: '',
                                    classname: 'btn btn-info btn-xs btn-ajax',
                                    url: 'shop/withdraw/agree',
                                    refresh:true,
                                    visible:function(row){
                                        if(row.status == 'created'){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'refuse',
                                    text: '拒绝',
                                    confirm:'确认拒绝打款吗?',
                                    icon: '',
                                    classname: 'btn btn-danger btn-xs btn-ajax',
                                    url: 'shop/withdraw/refuse',
                                    refresh:true,
                                    visible:function(row){
                                        if(row.status == 'created'){
                                            return true;
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
